

from django import forms
# 引入验证码的CaptchaField
#from captcha.fields import CaptchaField


# 表单
class RegisterForm(forms.Form):
    """注册信息的验证"""
    user = forms.CharField(required=True, error_messages={'required': '用户名不能为空.'})
    email=forms.EmailField(required=True,error_messages={'required': '邮箱不能为空.'})
    pwd = forms.CharField(required=True,
                          min_length=6,
                          error_messages={'required': '密码不能为空.', 'min_length': "至少6位"})
    pwd2 = forms.CharField(required=True,
                          min_length=6,
                          error_messages={'required': '密码不能为空.', 'min_length': "至少6位"})
    #captcha=CaptchaField(error_messages={'invalid':'验证码错误'})

    def clean(self):
        '''验证两次密码是否一致'''
        p1=self.cleaned_data.get('pwd')
        p2=self.cleaned_data.get('pwd2')
        if p1!=p2:
            raise forms.ValidationError('两次输入密码不一致')
        else:
            return self.cleaned_data

